package com.business.web.spring;


import com.business.domain.T_print_templete;
import com.business.service.T_print_templeteService;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

//import com.workflow.WorkFlowUtils;
//import com.business.mapper.T_print_templeteMapper;

@Controller
@RequestMapping("/t_print_templete")

public class T_print_templeteController
{
	private static Logger log = Logger.getLogger(T_print_templeteController.class.getName());

	@Resource
    private T_print_templeteService t_print_templeteService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_print_templeteMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_print_templete信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_print_templete")
	@ResponseBody
	public Pg getAllT_print_templete(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_print_templete t_print_templete = new T_print_templete();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_print_templete.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("templeteid")!=null&&!"".equals(request.getParameter("templeteid"))){
	        	t_print_templete.setTempleteid(request.getParameter("templeteid"));
	        }
			if(request.getParameter("key1")!=null&&!"".equals(request.getParameter("key1"))){
	        	t_print_templete.setKey1(request.getParameter("key1"));
	        }
			if(request.getParameter("key2")!=null&&!"".equals(request.getParameter("key2"))){
	        	t_print_templete.setKey2(request.getParameter("key2"));
	        }
			if(request.getParameter("key3")!=null&&!"".equals(request.getParameter("key3"))){
	        	t_print_templete.setKey3(request.getParameter("key3"));
	        }
			if(request.getParameter("key4")!=null&&!"".equals(request.getParameter("key4"))){
	        	t_print_templete.setKey4(request.getParameter("key4"));
	        }
			if(request.getParameter("key5")!=null&&!"".equals(request.getParameter("key5"))){
	        	t_print_templete.setKey5(request.getParameter("key5"));
	        }
			if(request.getParameter("key6")!=null&&!"".equals(request.getParameter("key6"))){
	        	t_print_templete.setKey6(request.getParameter("key6"));
	        }
			if(request.getParameter("key8")!=null&&!"".equals(request.getParameter("key8"))){
	        	t_print_templete.setKey8(request.getParameter("key8"));
	        }
			if(request.getParameter("key9")!=null&&!"".equals(request.getParameter("key9"))){
	        	t_print_templete.setKey9(request.getParameter("key9"));
	        }
			if(request.getParameter("key10")!=null&&!"".equals(request.getParameter("key10"))){
	        	t_print_templete.setKey10(request.getParameter("key10"));
	        }
			if(request.getParameter("key11")!=null&&!"".equals(request.getParameter("key11"))){
	        	t_print_templete.setKey11(request.getParameter("key11"));
	        }
			if(request.getParameter("key12")!=null&&!"".equals(request.getParameter("key12"))){
	        	t_print_templete.setKey12(request.getParameter("key12"));
	        }
			if(request.getParameter("key13")!=null&&!"".equals(request.getParameter("key13"))){
	        	t_print_templete.setKey13(request.getParameter("key13"));
	        }
			if(request.getParameter("key14")!=null&&!"".equals(request.getParameter("key14"))){
	        	t_print_templete.setKey14(request.getParameter("key14"));
	        }
			if(request.getParameter("key15")!=null&&!"".equals(request.getParameter("key15"))){
	        	t_print_templete.setKey15(request.getParameter("key15"));
	        }
			if(request.getParameter("val1")!=null&&!"".equals(request.getParameter("val1"))){
	        	t_print_templete.setVal1(request.getParameter("val1"));
	        }
			if(request.getParameter("val2")!=null&&!"".equals(request.getParameter("val2"))){
	        	t_print_templete.setVal2(request.getParameter("val2"));
	        }
			if(request.getParameter("val3")!=null&&!"".equals(request.getParameter("val3"))){
	        	t_print_templete.setVal3(request.getParameter("val3"));
	        }
			if(request.getParameter("val4")!=null&&!"".equals(request.getParameter("val4"))){
	        	t_print_templete.setVal4(request.getParameter("val4"));
	        }
			if(request.getParameter("val5")!=null&&!"".equals(request.getParameter("val5"))){
	        	t_print_templete.setVal5(request.getParameter("val5"));
	        }
			if(request.getParameter("val6")!=null&&!"".equals(request.getParameter("val6"))){
	        	t_print_templete.setVal6(request.getParameter("val6"));
	        }
			if(request.getParameter("val7")!=null&&!"".equals(request.getParameter("val7"))){
	        	t_print_templete.setVal7(request.getParameter("val7"));
	        }
			if(request.getParameter("val8")!=null&&!"".equals(request.getParameter("val8"))){
	        	t_print_templete.setVal8(request.getParameter("val8"));
	        }
			if(request.getParameter("val9")!=null&&!"".equals(request.getParameter("val9"))){
	        	t_print_templete.setVal9(request.getParameter("val9"));
	        }
			if(request.getParameter("val10")!=null&&!"".equals(request.getParameter("val10"))){
	        	t_print_templete.setVal10(request.getParameter("val10"));
	        }
			if(request.getParameter("val11")!=null&&!"".equals(request.getParameter("val11"))){
	        	t_print_templete.setVal11(request.getParameter("val11"));
	        }
			if(request.getParameter("val12")!=null&&!"".equals(request.getParameter("val12"))){
	        	t_print_templete.setVal12(request.getParameter("val12"));
	        }
			if(request.getParameter("val13")!=null&&!"".equals(request.getParameter("val13"))){
	        	t_print_templete.setVal13(request.getParameter("val13"));
	        }
			if(request.getParameter("val14")!=null&&!"".equals(request.getParameter("val14"))){
	        	t_print_templete.setVal14(request.getParameter("val14"));
	        }
			if(request.getParameter("val15")!=null&&!"".equals(request.getParameter("val15"))){
	        	t_print_templete.setVal15(request.getParameter("val15"));
	        }
			if(request.getParameter("key16")!=null&&!"".equals(request.getParameter("key16"))){
	        	t_print_templete.setKey16(request.getParameter("key16"));
	        }
			if(request.getParameter("key17")!=null&&!"".equals(request.getParameter("key17"))){
	        	t_print_templete.setKey17(request.getParameter("key17"));
	        }
			if(request.getParameter("key18")!=null&&!"".equals(request.getParameter("key18"))){
	        	t_print_templete.setKey18(request.getParameter("key18"));
	        }
			if(request.getParameter("key19")!=null&&!"".equals(request.getParameter("key19"))){
	        	t_print_templete.setKey19(request.getParameter("key19"));
	        }
			if(request.getParameter("key20")!=null&&!"".equals(request.getParameter("key20"))){
	        	t_print_templete.setKey20(request.getParameter("key20"));
	        }
			if(request.getParameter("val16")!=null&&!"".equals(request.getParameter("val16"))){
	        	t_print_templete.setVal16(request.getParameter("val16"));
	        }
			if(request.getParameter("val17")!=null&&!"".equals(request.getParameter("val17"))){
	        	t_print_templete.setVal17(request.getParameter("val17"));
	        }
			if(request.getParameter("val18")!=null&&!"".equals(request.getParameter("val18"))){
	        	t_print_templete.setVal18(request.getParameter("val18"));
	        }
			if(request.getParameter("val19")!=null&&!"".equals(request.getParameter("val19"))){
	        	t_print_templete.setVal19(request.getParameter("val19"));
	        }
			if(request.getParameter("val20")!=null&&!"".equals(request.getParameter("val20"))){
	        	t_print_templete.setVal20(request.getParameter("val20"));
	        }
      	    if(request.getParameter("id")!=null&&!"".equals(request.getParameter("id"))){
	        	t_print_templete.setId(new Integer(request.getParameter("id")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_print_templete.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_print_templete.setEnddate(request.getParameter("enddate"));
	        }
	        t_print_templete.setStartNo( startIndex );
	        t_print_templete.setPageSize( pageSize );
	        t_print_templete.setEndNo( pageSize );
	    	List<T_print_templete> findAll = t_print_templeteService.findAll(t_print_templete);
	        int totalCount = t_print_templeteService.findCountAll(t_print_templete);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_print_templeteList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_print_templeteList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_print_templete信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_print_templete")
	@ResponseBody
	public JsonVO saveT_print_templete(T_print_templete t_print_templete, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_print_templeteService.save(t_print_templete)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_print_templete信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_print_templete
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_print_templete")
	@ResponseBody
	public JsonVO updateT_print_templete(T_print_templete t_print_templete, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_print_templete t_print_templeteTemp = t_print_templeteService.findById(t_print_templete);
		//t_print_templeteTemp.setXXX(t_print_templete.getXXX());
		//if(t_print_templeteService.update(t_print_templeteTemp)){

		if(t_print_templeteService.update(t_print_templete)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_print_templete单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_print_templete json格式字符串
	 */
	@RequestMapping("/getT_print_templete")
	@ResponseBody
	public T_print_templete getT_print_templete(Integer id,HttpServletRequest request){
		T_print_templete t_print_templete = new T_print_templete();
		t_print_templete.setId(id);
		return t_print_templeteService.findById(t_print_templete);
	}

	/**
	 * 5、删除T_print_templete根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_print_templete")
	@ResponseBody
	public JsonVO delT_print_templete(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_print_templete t_print_templete = new T_print_templete();
		t_print_templete.setId(id);

		if(t_print_templeteService.delete(t_print_templete)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_print_templete/toT_print_templeteList查询所有数据页面
	 *  return /WEB-INF/views/business/printtemplete/t_print_templete/t_print_templeteList.jsp
	 */
    @RequestMapping(value = "/toT_print_templeteList")
    public String toT_print_templeteList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_print_templete/t_print_templeteList.jsp------");
        return "business/t_print_templete/t_print_templeteList";
    }

	/**
	 * 7、新增、修改、详情页面t_print_templete/toT_print_templeteCurd跳转
     * business/printtemplete/t_print_templete/T_print_templeteCurd.jsp
	 */
    @RequestMapping(value = "/toT_print_templeteCurd")
    public String toT_print_templeteCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_print_templete/t_print_templeteCurd.jsp------");
        return "business/t_print_templete/t_print_templeteCurd";
    }

    /**
	 * 8、批量删除T_print_templete根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_print_templeteBatch")
	public String delT_print_templeteBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_print_templete t_print_templete = new T_print_templete();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_print_templete.setId(new Integer(ids[i]).intValue());
			t_print_templeteService.delete(t_print_templete);
		}
		if(j==ids.length){
			log.debug("------t_print_templete批量删除成功！------");
		}else{
			log.error("------t_print_templete批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_print_templete/getAllT_print_templete";
	}
*/



}









